footer.init();
header.init('用户登录');

window.onload = function(){
	$('body').on('click','#tel',function(){
			var tel = $(this).val();
			var reg=/^1[3,5,7,8,9]\d{9}$/;
			if(tel == "" || !reg.test(tel)){
				layer.msg('请输入正确的手机号');
				return false;
			}
	});
	$('body').on('click','#sendToTel',function(){
		$('#getcode').val('');
		var btn = $(this);
		var tel = $('#tel').val();
		console.log(tel);
		var reg=/^1[3,5,7,8,9]\d{9}$/;
		var time = 60;
		if(tel == "" || !reg.test(tel)){
			layer.msg('请输入正确的手机号');
			return false;
		}
		app.ajax(
			'/Index/Index/send',
			{
				mobile : tel
			},function(res){
				 $("#sendToTel").text("发送成功");
				 var time = 60;
               hander = setInterval(function () {
                    if (time <= 0) {
                        canSend = true;
                        clearInterval(hander);
                        btn.text("获取验证码");
                        btn.removeAttr("disabled");
                    }
                    else {
                        canSend = false;
                        time--;
                        btn.attr({ "disabled": "disabled" });
                        btn.text( time + "s后可重新发送");
                }
			},1000);
		});
	});
	
	$('body').on('click','.login',function(){
		var tel = $('#tel').val();
		var code = $('#getcode').val();
		var reg=/^1[3,5,7,8,9]\d{9}$/;
		if(tel == "" || !reg.test(tel)){
			layer.msg('请输入正确的手机号');
			return false;
		}
		app.ajax(
			'/Member/Login/register',
			{
				mobile : tel,
				code   :code
			},function(res){
				
				if(res.code==200){
					layer.msg(res.msg);
					setTimeout(function(){
						history.go(-1);
					},2000);
				}
			}
		)
	});

}
